package juc.mythread.create;

import juc.mythread.tools.SleepTools;

/**
 * @ClassName TestInterrupt
 * @PackageName mythread.create
 * @projectName myThread
 * @Description 
 * @Author games
 * @Date 2025/8/25 下午2:38
 * @Version 1.0
 */
public class TestInterrupt {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(500);
                    System.out.println("线程正在执行");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("线程被中断");
                    //Thread.currentThread().interrupt(); // 恢复中断状态
                    //JVM 会自动清除该线程的中断标志，即 isInterrupted = false。
                    System.out.println("--" + Thread.currentThread().isInterrupted());
                    break;
                }
            }
        });
        t.start();
        SleepTools.second(2);
        t.interrupt();
        System.out.println("--t" + t.isInterrupted());
    }
}
